package beanstao.util.store.database;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import beanstao.util.Formula;

public class Columns implements List<Column>
{
	public static Columns ME(Column... fields)
	{
		Columns list = new Columns();
		for (Column column : fields)
			list.add(column);
		return list;
	}

	/**
	 * 当选择所有字段。即我们一般称谓的： Select星
	 * 
	 * @return
	 */
	public static Columns ME_ALL()
	{
		Column selectField = new Column();
		selectField.append(new Formula("*"));
		Columns list = Columns.ME(selectField);
		return list;
	}

	private Columns()
	{

	}

	public StringBuilder toStringBuilder(Fields columns)
	{
		StringBuilder sb = new StringBuilder();
		for (Iterator<Column> it = _List.iterator(); it.hasNext();)
		{
			sb.append(it.next().toStringBuilder(columns));
			if (it.hasNext())
				sb.append(",");
		}
		return sb;
	}

	public String toSql(Fields domain)
	{
		return this.toStringBuilder(domain).toString();
	}

	// =======================

	private final ArrayList<Column> _List = new ArrayList<Column>();

	@Override
	public boolean add(Column e)
	{
		return _List.add(e);
	}

	@Override
	public void add(int index, Column element)
	{
		_List.add(index, element);
	}

	@Override
	public boolean addAll(Collection<? extends Column> c)
	{
		return _List.addAll(c);
	}

	@Override
	public boolean addAll(int index, Collection<? extends Column> c)
	{
		return _List.addAll(index, c);
	}

	@Override
	public void clear()
	{
		_List.clear();
	}

	@Override
	public boolean contains(Object o)
	{
		return _List.contains(o);
	}

	@Override
	public boolean containsAll(Collection<?> c)
	{
		return _List.containsAll(c);
	}

	@Override
	public Column get(int index)
	{
		return _List.get(index);
	}

	@Override
	public int indexOf(Object o)
	{
		return _List.indexOf(o);
	}

	@Override
	public boolean isEmpty()
	{
		return _List.isEmpty();
	}

	@Override
	public Iterator<Column> iterator()
	{
		return _List.iterator();
	}

	@Override
	public int lastIndexOf(Object o)
	{
		return _List.lastIndexOf(o);
	}

	@Override
	public ListIterator<Column> listIterator()
	{
		return _List.listIterator();
	}

	@Override
	public ListIterator<Column> listIterator(int index)
	{
		return _List.listIterator(index);
	}

	@Override
	public boolean remove(Object o)
	{
		return _List.remove(o);
	}

	@Override
	public Column remove(int index)
	{
		return _List.remove(index);
	}

	@Override
	public boolean removeAll(Collection<?> c)
	{
		return _List.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c)
	{
		return _List.retainAll(c);
	}

	@Override
	public Column set(int index, Column element)
	{
		return _List.set(index, element);
	}

	@Override
	public int size()
	{
		return _List.size();
	}

	@Override
	public List<Column> subList(int fromIndex, int toIndex)
	{
		return _List.subList(fromIndex, toIndex);
	}

	@Override
	public Object[] toArray()
	{
		return _List.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a)
	{
		return _List.toArray(a);
	}

}
